import io from 'socket.io-client'
import store from '@/store'
//import store from '@/store'

const socket = io()

socket.on('connect',()=> {
    console.log('和服务器建立链接')
})


socket.on('newRoom',(room)=>{
    store.commit('updateRoom',room)
})

socket.on('playrooms',(rooms) => {
    console.log('更新房间')
    store.commit('updateRooms',rooms)
})
socket.on('joinroom',(room)=>{
    console.log('加入房间')
    //console.log(rooms)
    store.commit('updateRoom',room)
})

socket.on('passworderror',()=>{
    console.log('收到密码错误')
    //console.log(rooms)
    store.commit('updatePass',false)
})
socket.on('getword',(word,owner)=>{
    console.log('收到新词')
    //console.log(rooms)
    store.commit('updatewordowner',owner)
    store.commit('updateword',word)
})

socket.on('words',(word)=>{
    console.log('收到词语')
    //console.log(rooms)
    store.commit('updateWords',word)
})

socket.on('getline',(lines,owner)=>{
    console.log('收到绘图')
    //console.log(rooms)
    store.commit('updateLines',lines)
    store.commit('updatedrawowner',owner)
})

socket.on('finishturn',()=>{
    console.log('更新图片')
    //console.log(rooms)
    store.commit('updateAnotherLines')
})

socket.on('getNewWord',(word,owner)=>{
    console.log('更新词语')
    //console.log(rooms)
    store.commit('updateword',word)
    store.commit('updatewordowner',owner)
})

socket.on('gethistory',(user)=>{
    console.log('更新历史')
    //console.log(rooms)
    store.commit('updatehistory',user)
})
export default socket